home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 016a / gofer221.zip / QUEENS < prev    next >
Text File  |  1991-11-20  |  595b  |  17 lines

  1. -- The 8-queens problem from Bird and Wadler's book.
  2. --
  3. -- Be warned: printing out the complete list of solutions (all 92 of them)
  4. -- by evaluating: layn (map show' (queens 8)) takes well over 1 million
  5. -- reductions and uses nearly 2.5 million cells... it may take some time to
  6. -- execute on slower systems! :-)
  7.  
  8. queens 0          = [[]]
  9. queens (m+1)      = [ p++[n] | p<-queens m, n<-[1..8], safe p n ]
  10.  
  11. safe p n          = all not [ check (i,j) (m,n) | (i,j) <- zip [1..] p ]
  12.                     where m = 1 + length p
  13.  
  14. check (i,j) (m,n) = j==n || (i+j==m+n) || (i-j==m-n)
  15.  
  16.  
  17.